<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>网页聊天室</title>
    <link rel="stylesheet" href="./css/common.css">
    <link rel="stylesheet" href="./css/login.css">
</head>
<body>
    <div class="main">
        <!-- 导航栏 -->
        <div class="nav">
            <h3>网页聊天室</h3>
        </div>
        <div class="dialog_containner">
            <div class="dialog">
                <h3>登录</h3>
                <div class="row">
                    <span>用户名</span><input type="text" id="userName">
                </div>
                <div class="row">
                    <span>密码</span><input type="password" id="password">
                </div>
                <button id="login">登录</button><br>
                <a href="registry.html">注册</a>
            </div>
        </div>
    </div>


    <script src="./js/jquery.min.js"></script>
    <script>
        let loginBtn = document.querySelector('.main .dialog #login')
        loginBtn.onclick = function() {
            let userName = document.querySelector('.main .dialog #userName').value
            let password = document.querySelector('.main .dialog #password').value
            $.ajax({
                type: 'post',
                url: '/user/login',
                data: {
                    userName: userName,
                    password: password
                },
                success: function(result) {
                    if (result.status == 200 && result.data) {
                        alert('登录成功!');
                        location.href = 'client.html'
                    }else {
                        alert(result.message);
                    }
                }
            });
        }
    </script>
</body>
</html>